//
//	 ______    ______    ______    
//	/\  __ \  /\  ___\  /\  ___\   
//	\ \  __<  \ \  __\_ \ \  __\_ 
//	 \ \_____\ \ \_____\ \ \_____\ 
//	  \/_____/  \/_____/  \/_____/ 
//
//	Powered by BeeFramework
//
//
//  GuideBoard.m
//  iHeima
//
//  Created by he chao on 6/26/14.
//  Copyright (c) 2014 leon. All rights reserved.
//

#import "GuideBoard.h"

#pragma mark -

@interface GuideBoard()
{
	//<#@private var#>
}
@end

@implementation GuideBoard

- (void)load
{
}

- (void)unload
{
}

#pragma mark - Signal

ON_CREATE_VIEWS( signal )
{
    self.view.backgroundColor = [UIColor whiteColor];
    
    if (!pageViewController) {
        pageViewController = [[CVScrollPageViewController alloc] init];
    }
    pageViewController.indicatorStyle = CVScrollPageIndicatorStyleHigh;
    //pageViewController.view.backgroundColor = [UIColor colorWithRed:228.0/255 green:228.0/255 blue:228.0/255 alpha:1];
    pageViewController.frame = self.bounds;
    [pageViewController setDelegate:self];
    [self.view addSubview:pageViewController.view];
    pageViewController.pageCount = 4;
    [pageViewController reloadData];
    [pageViewController changePage:pageViewController.pageControl];
    pageViewController.pageControlFrame = CGRectMake(0, self.view.frame.size.height-20, 320, 20);
}

ON_DELETE_VIEWS( signal )
{
}

ON_LAYOUT_VIEWS( signal )
{
}

ON_WILL_APPEAR( signal )
{
}

ON_DID_APPEAR( signal )
{
}

ON_WILL_DISAPPEAR( signal )
{
}

ON_DID_DISAPPEAR( signal )
{
}

ON_SIGNAL3( BeeUINavigationBar, LEFT_TOUCHED, signal )
{
}

ON_SIGNAL3( BeeUINavigationBar, RIGHT_TOUCHED, signal )
{
}

- (void)didScrollToPageAtIndex:(NSUInteger)index {
    NSLog(@"zzzz");
    if (pageViewController.scrollView.contentOffset.x>3*self.viewWidth+20) {
        NSLog(@"%.f",pageViewController.scrollView.contentOffset.x);
        [self.stack popBoardAnimated:NO];
        NSLog(@"记录第一次登陆");
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"isFirstEnter"];
    }
    //    NSMutableArray *array = [dictBook valueForKey:@"pages"];
    //    NSMutableDictionary *dict = [array objectAtIndex:index];
    //    labelDescription.text = [dict valueForKey:@"description"];
    //
    //    CGSize constraintSize;
    //    constraintSize.height = MAXFLOAT;
    //    constraintSize.width = labelDescription.frame.size.width;
    //    CGSize stringSize = [labelDescription.text sizeWithFont:labelDescription.font constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];
    //    labelDescription.frame = CGRectMake(labelDescription.frame.origin.x, labelDescription.frame.origin.y, stringSize.width, stringSize.height);
    //
    //    [myScrollView setContentSize:CGSizeMake(myScrollView.frame.size.width, labelDescription.frame.size.height+20)];
}

- (UIView *)scrollPageView:(id)scrollPageView viewForPageAtIndex:(NSUInteger)index {
    UIView *pageView;
    pageView = (UIView *)[scrollPageView dequeueReusablePage:index];
    if (nil == pageView) {
        pageView = [[UIView alloc] initWithFrame:self.bounds];
        
        UIImageView *imgContent = [[UIImageView alloc] initWithFrame:self.bounds];
        NSString *strName = IS_SCREEN_4_INCH?[NSString stringWithFormat:@"guide%d_ip5.jpg",index]:[NSString stringWithFormat:@"guide%d.jpg",index];
        UIImage *image = IMAGESTRING(strName);
        imgContent.image = image;
        [pageView addSubview:imgContent];
        /*
        if (index != 2) {
            UIImageView *imgContent = [[UIImageView alloc] initWithFrame:self.view.bounds];
            imgContent.image = [UIImage imageNamed:IS_SCREEN_4_INCH?[NSString stringWithFormat:@"guide%d_ip5.jpg",index+1]:[NSString stringWithFormat:@"guide%d.jpg",index+1]];
            [pageView addSubview:imgContent];
        }
        else {
            imgRight = [[UIImageView alloc] initWithFrame:self.view.bounds];
            imgRight.image = [UIImage imageNamed:iPhone5?@"splash_right_ip5":@"splash_right"];
            [pageView addSubview:imgRight];
            
            imgLeft = [[UIImageView alloc] initWithFrame:self.view.bounds];
            imgLeft.image = [UIImage imageNamed:iPhone5?@"splash_left_ip5":@"splash_left"];
            [pageView addSubview:imgLeft];
            
            //,*imgLeft;
            
            btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
            [btn addTarget:self action:@selector(clickEnterBtn) forControlEvents:UIControlEventTouchUpInside];
            [btn setBackgroundImage:[UIImage imageNamed:@"go_n"] forState:UIControlStateNormal];
            [btn setBackgroundImage:[UIImage imageNamed:@"go_p"] forState:UIControlStateHighlighted];
            [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [btn setTitle:@"开始使用" forState:UIControlStateNormal];
            btn.frame = CGRectMake(110, self.view.frame.size.height - 100, 100, 31);
            [pageView addSubview:btn];
        }*/
        
    }
    return pageView;
}


- (void)clickEnterBtn{
    
    printf("click button\n");
    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"isFirstEnter"];
}

@end
